var http = require('../../utils/http.js')
var util = require('../../utils/util.js')
var localstorage = require('../../utils/localstorage.js')
var appInstance = getApp()
var page = 1;
var pageSize = 15;

Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    selectXiLie:   {id:0,title:"所有系列"},
   
    XiLieArr:[],
    //
    datalist:[],
    isMore: true,
    searchWork:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getdatalist(
      this.data.selectXiLie,
    );
  
   this.getXiLielist();
    
  },

  getXiLielist() {
    var _this = this;
    var postdata = {
      "Page": 1,
      "PageSize": 9999
    }
    http.request({
      url: 'car_SeXiServiceApi/page',
      method: "Post",
      data: postdata,
      callBack: (res) => {
        // console.log(res)
        let newArr = res.result.items;
        let totalPages = res.result.totalPages

        wx.stopPullDownRefresh()

        _this.setData({
          XiLieArr: [...[_this.data.selectXiLie], ...newArr],
        })


      }
    })
  },

 

   bindPickerChangeXilie:function(e)
   {
    var index=e.detail.value
    var sdata=this.data.XiLieArr[index]
    if(sdata==undefined)
    {
      return;
    }
     this.setData({
      selectXiLie: sdata
     })
     page=1;
     this.data.datalist=[]
     this.getdatalist(
       sdata,
     );
   },


   
onReachBottom() {
  if (this.data.isMore) {
   
    page = page + 1;
    this.getdatalist(
      this.data.selectXiLie,
    );
  }
},

onPullDownRefresh()
{
  this.setData({
    datalist: [],
  })
  page = 1;
  this.getdatalist(
    this.data.selectXiLie,
  );

},

   getdatalist:function(selectXiLie)
   {
    var _this = this;
    this.setData({
      isloading:true
    })
    var postdata = {
      "Page": page,
      "PageSize": pageSize,
      "sexiId":selectXiLie.id,
      "isRandom":selectXiLie.id==0
    }
    http.request({
      url: 'car_caseServiceApi/page',
      method: "Post",
      data: postdata,
      callBack: (res) => {
       
         let newArr = res.result.items;
         let totalPages=res.result.totalPages
        
         wx.stopPullDownRefresh()
       
         _this.setData({
          isloading:false,
         datalist: [..._this.data.datalist, ...newArr],
           isMore:page<totalPages
         })


      }
    })
   },


   onclickItem:function(e)
   {
    // console.log(e.currentTarget.dataset.id)
     var id=e.currentTarget.dataset.id;
     var title=e.currentTarget.dataset.title;
     wx.navigateTo({
       url: '/pages/case/details?id='+id+'&title='+title,
     })
   },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

 

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})